/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.uoc.tfc.exuoc.controladors;


import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.HibernateException;

/**
 * Hibernate Utility class with a convenient method to get Session Factory object.
 *
 * @author emoreno
 */
public class HibernateUtils {
    private static final SessionFactory sessionFactory;
    private GestorLogs  log=GestorLogs .getLogger(this.getClass().getName());

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            sessionFactory = new AnnotationConfiguration()
                    .configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            GestorLogs .getLogger(HibernateUtils.class.getName())
                    .error("Error de creació de L'API Hibernate: "
                    +ex.getLocalizedMessage());

            throw new HibernateException(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
       return sessionFactory;
    }
}
